# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

pkgname=limesuite
pkgver=22.09.1
pkgrel=3
pkgdesc='Driver and GUI for LMS7002M-based SDR platforms (LimeSDR, etc.)'
arch=('loong64' 'x86_64')
url='https://github.com/myriadrf/LimeSuite'
license=('Apache')
depends=('sqlite3' 'wxwidgets-gtk3' 'freeglut' 'libusb' 'soapysdr' 'wget' 'gnuplot' 'glew' 'fltk')
makedepends=('cmake' 'doxygen' 'octave')
optdepends=('octave: Octave plugin')
provides=('soapylms7')
conflicts=('soapylms7')
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha512sums=('526d99f8f835bfab021b29b7ffc5bf49d05d7b2211646c3474c35b8dcf9bfb2555b024bf5fa7bc7db2042003415e00fb0423f3ba15244df6940023304c9cdaff')

prepare() {
  cd LimeSuite-$pkgver

  sed -i 's|MODE="660", GROUP="plugdev"|MODE="666"|g' udev-rules/64-limesuite.rules
}

build() {
  mkdir -p LimeSuite-$pkgver/build
  cd LimeSuite-$pkgver/build

  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DENABLE_UTILITIES=True \
    -DENABLE_LIME_UTIL=True \
    -DCMAKE_SKIP_RPATH=True \
    -DENABLE_DESKTOP=False \
    -DENABLE_SOAPY_LMS7=True \
    -DENABLE_PCIE_XILLYBUS=True \
    -DENABLE_QUICKTEST=True \
    -DENABLE_MCU_TESTBENCH=True \
    -DENABLE_FTDI=True \
    -DENABLE_FX3=True \
    -DENABLE_STREAM_UNITE=True \
    -DENABLE_EXAMPLES=True \
    -DENABLE_HEADERS=True \
    -DENABLE_GUI=True \
    -DENABLE_OCTAVE=True \
    -DENABLE_API_DOXYGEN=True \
    -DLIME_SUITE_EXTVER=$pkgver

#    -DENABLE_EVB7COM=True \
#    -DENABLE_REMOTE=True \

  make
}

package() {
  cd LimeSuite-$pkgver/build

  make DESTDIR="$pkgdir" install

  # Install udev rules
  install -Dm 644 ../udev-rules/64-limesuite.rules "$pkgdir"/etc/udev/rules.d/64-limesuite.rules

  # Install icons and .desktop file
  install -Dm 644 ../Desktop/lime-suite-128.png "$pkgdir"/usr/share/pixmaps/lime-suite.png
  install -Dm 755 ../Desktop/lime-suite.desktop "$pkgdir"/usr/share/applications/lime-suite.desktop

  # Install documentation
  install -dm 755 "$pkgdir"/usr/share/doc/$pkgname
  cp -r --no-preserve=ownership ../docs/LMS_API_Documentation/* "$pkgdir"/usr/share/doc/$pkgname
}

